Skip to content

Keep a killed program's tree job until it's completed, so -KillTreeOnExit doesn't warn after the kit's own kill - #122

Merged
HalRiveria merged 8 commits into
mainfrom
fix/killtree-keeps-tree-job
Dec 3, 2026
Merged

HalRiveria merged 8 commits into
mainfrom
fix/killtree-keeps-tree-job

Conversation

@HalRiveria-Bot

@HalRiveria-Bot HalRiveria-Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong: with -KillTreeOnExit, a program the kit killed got the warning "-KillTreeOnExit can't stop what process N left running: the program has no Job Object of its own ...". That covered a kill for the dispatcher's or batch's time limit, for Invoke-PkProcessWithTimeout's limit, and in an abort's force-stop. The kill goes through KillTree, which closed the program's tree job once it had ended it. So when -KillTreeOnExit then ended the exited program's tree, Stop-PkExitedJobTree found no tree job and took the no-tree branch. Nothing was left running; only the warning was wrong. This has been there since 4.2.

What changed:

  • KillTree no longer closes the tree job. A second KillTree ends an empty job, which succeeds, so Stop-PkExitedJobTree stays quiet.
  • Complete-PkProcess still closes the tree job.
  • The dispatcher's force-stop (Stop-PkJobProcess) and Invoke-PkProcessWithTimeout's cleanup now close it themselves, since they dispose a killed program without completing it.
  • A program that's killed but never completed (a -JobFinalize that doesn't call Complete-PkProcess, or a direct Stop-PkProcessTree) keeps its tree job until garbage collection, as an unkilled one already did.
  • This changes the C#. 4.3 already bumped TypesVersion in End what a program left running when its start is rolled back after it exited #115, so it doesn't change again.

Also in this PR: a line in the README's Limits. A program whose path is longer than 260 characters can't be started, even with long paths enabled and in the \\?\ form. Windows refuses it with "The filename or extension is too long" (or, for a plain path on PowerShell 7, "The system cannot find the file specified"). I checked this with a 369-character path on Windows PowerShell 5.1 and PowerShell 7.

Also: a harness timing fix. This PR's first CI run failed one assertion under Windows PowerShell 5.1: "a -JobFinalize that throws gets no -JobAbortCleanup for its finished job, only for the killed one (... 1 left ...)". It counted leftover pings right after the dispatcher's teardown kill, and ending a Job Object returns before Windows has torn its processes down. That's the same pattern #120 fixed in one test. Five other tests counted the same way, so all six now use one helper, Get-LimitPingLeft, which waits up to 5 seconds for the pings to go and still fails one that survives.

How it was tested: harness section BJ runs each of the three kills with -KillTreeOnExit and checks the ping is gone with no warning. Section BF's check that Stop-PkProcessTree lets go of the tree job now expects the tree job to stay after the kill, a second KillTree to succeed, and the release at Complete-PkProcess.

Before the fix (Windows PowerShell 5.1 and PowerShell 7, the same on both):

[FAIL] a time-limit kill in a batch with -KillTreeOnExit kills the program and doesn't warn about its tree (as expected: True, pings left 0, 1 warning(s): [WARNING] -KillTreeOnExit can't stop what process N left running: the program has no Job Object of its own ...)
[FAIL] Invoke-PkProcessWithTimeout's limit with -KillTreeOnExit kills the program and doesn't warn about its tree (... 1 warning(s) ...)
[FAIL] an abort's force-stop with -KillTreeOnExit kills the program and doesn't warn about its tree (... 1 warning(s) ...)

After: all three pass with 0 warnings, and so does the updated BF check. Build/Update-ParallelKitCSharp.ps1 -Compile builds the C# with no warnings under both csc.exe (C# 5) and the .NET SDK (LangVersion 5).

Full harness: all 779 assertions pass on Windows PowerShell 5.1 and on PowerShell 7.

The dispatcher checks for an abort once per pass, and its start loop read only the token, which that check cancels. So a Ctrl+C landing while the loop was starting programs, or a -JobStarter that requested an abort, still filled every free slot on that pass. The start loop now also reads the abort flag before each job, ahead of the shared budget's Wait(0) so no slot is taken for a job that won't start. Harness section O covers a -JobStarter that requests an abort, with a plain limit and with a shared budget.
The test that kills a live tree listed beside a disposed process counted leftover pings right after Stop-PkProcessTree returned. Ending a Job Object returns before Windows has finished tearing its processes down, so on a CI runner the ping was still listed once. It now waits up to 5 seconds for it to go, as the other kill tests do.
…Exit doesn't warn after the kit's own kill

With -KillTreeOnExit, a program the kit killed (for its time limit, Invoke-PkProcessWithTimeout's limit, or an abort's force-stop) got the warning that it "has no Job Object of its own". KillTree closed the program's tree job once it had ended it, so -KillTreeOnExit, ending it again once the program had exited, found no tree job.

KillTree now leaves the tree job open: a second KillTree ends an empty job and succeeds, quietly. Complete-PkProcess closes it as before, and so do the force-stop and Invoke-PkProcessWithTimeout's cleanup, which dispose a killed program without completing it. Harness section BJ covers the three kills; BF's check that a kill releases the tree job now expects the release at Complete-PkProcess, and a second KillTree to succeed.

The README's Limits also says a program whose path is over 260 characters can't be started: Windows refuses it, long paths enabled or not.
… every dispatcher kill test

On CI, 'a -JobFinalize that throws gets no -JobAbortCleanup for its finished job' failed under Windows PowerShell 5.1 with 1 ping left: it counted leftover pings right after the dispatcher's teardown kill, and ending a Job Object returns before Windows has torn its processes down. Five other tests count the same way. They now all use one helper, Get-LimitPingLeft, which waits up to 5 seconds for the pings to go, and still fails one that survives.
@HalRiveria
HalRiveria merged commit f6787fc into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/killtree-keeps-tree-job branch December 3, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants